package com.wyix.entity;


import java.math.BigDecimal;

/**
 * @author wangdx
 * @date 2025/8/1
 * @description 订单类
 */
public class Order {
    private int orderId; // 订单编号，使用 int 类型
    private byte quantity; // 商品数量，使用 byte 类型
    private Product product;
    private BigDecimal totalAmount; // 订单总金额，使用 BigDecimal 避免精度丢失

    public Order(int orderId, byte quantity, Product product) {
        this.orderId = orderId;
        this.quantity = quantity;
        this.product = product;
        // 使用 BigDecimal 计算订单总金额
        this.totalAmount = new BigDecimal(product.price).multiply(new BigDecimal(quantity));
    }

    @Override
    public String toString() {
        return "Order{orderId=" + orderId + ", quantity=" + quantity + ", totalAmount=" + totalAmount + "}";
    }
}
